<template>
  <div class="nav-wrap">
    <div
      v-for="(item,index) in navs"
      :key="index"
      :class="{'nav-item':true,'nav-item-active':currNav === index}"
      @click="toPage(item,index)"
    >{{ item.name }}</div>
  </div>
</template>

<script>
export default {
  name: 'Nav',
  data() {
    return {
      currNav: 0,
      currtitle: '',
      navs: [
        {
          name: '示例页面1',
          path: '/page1'
        },
        {
          name: '示例页面2',
          path: '/page2'
        },
        {
          name: '示例页面3',
          path: '/page3'
        },
        {
          name: '元素页',
          path: '/element'
        }
      ]
    }
  },
  beforeDestroy() {

  },
  mounted() {
    this.setNav()
  },
  methods: {
    setNav() {
      this.navs.forEach((item, index) => {
        if (item.path === this.$route.path) {
          this.currNav = index
          this.currtitle = item.name
        }
      })
    },
    toPage(item, index) {
      this.currtitle = item.name
      this.currNav = index
      this.$router.push(item.path)
    }
  }
}
</script>

<style scoped lang="less">
.nav-wrap{
  width: 500px;
  margin-left: calc(100% - 500px);
  padding: 0 50px;
  height: 100%;
  min-height: 0.47rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: rgba(155, 159, 163, .1);
  .nav-item{
    padding: 0 0.1rem;
    color: #fff;
  }
  .nav-item:hover{
    cursor: pointer;
  }
  .nav-item-active{
    color: rgb(179,163,104);
    border: 1px solid rgb(179,163,104);
  }

}

</style>
